<?php

	/**
	 * File : mini_toolbar.php
	 * Description : Définition et fonctions du composant ktkMiniToolbar
	 * Date : 07.08.2012 15:16:23
	 * 
	 * This file is part of Phenix.  Phenix is free software: you can
	 * redistribute it and/or modify it under the terms of the GNU General Public
	 * License as published by the Free Software Foundation, version 2.
	 *
	 * This program is distributed in the hope that it will be useful, but WITHOUT
	 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
	 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
	 * details.
	 *
	 * You should have received a copy of the GNU General Public License along with
	 * this program; if not, write to the Free Software Foundation, Inc., 51
	 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
	 *
	 * Nils Schaetti <n.schaetti@gmail.com>
	**/

	/*
	 * Fichier requis
	 */
	 require_once('mini_toolbar_button.php');
	 
	 /**
	  * Classe représentant une mini toolbar
	  */
	class ktkMiniToolbar implements KTKWidgets
	{
		
		/*************
		 * Propriétés
		**************/
		
		/*
		 * Boutons de la barre
		 */
		private $Buttons;
		
		/**
		 * Titre de la mini toolbar affichée
		 */
		private $Title = '';
		
		/**
		 * Le nom de la mini toolbar
		 */
		private $Name;
		
		/*************
		 * Fonctions
		 *************/
		 
		/*
		 * Constructeur
		 */
		 public function ktkMiniToolbar($Name,$title)
		 {
			 $this->Buttons = array();
			 $this->Title = $title;
			 $this->Name = $Name;
		 }
		 
		 /**
		  * Ajoute un bouton à la barre
		  */
		  public function addButton($name, $button)
		  {
			  $this->Buttons[$name] = $button;
		  }
		 
		 /*
		  * Renvoi le code de la barre
		  */
		  public function getCode()
		  {
			  // Code de la barre
			  $code = <<< _DELIMITER_
			  <div class="ktkMiniToolbarPageTitle" id="{$this->Name}">@@_TITLE_@@</div>
				<div class="ktkMiniToolbarPageAction">
					@@_BUTTONS_@@
				</div>
_DELIMITER_;
				
				// Remplace le titre
				$code = str_replace('@@_TITLE_@@', $this->Title, $code);
				
				// Code des boutons
				$buttons_code = '';
				
				// Pour chaque boutons
				foreach($this->Buttons as $button)
				{
					$buttons_code .= $button->getCode();
				}
				
				// Remplace le tag
				$code = str_replace('@@_BUTTONS_@@', $buttons_code, $code);
				
				return $code;
		  }
		  
		  /**
		   * Cache un bouton
		   */
		public function hideButton($name)
		{
			$button = $this->Buttons[$name];
			$button->setHidden();
		}
		
		/**
		 * Rend un bouton visible
		 */
		public function showButton($name)
		{
			$this->Buttons[$name]->setVisible();
		}
		  
		  /**
		   * Affiche le widget
		   */
		  public function Show()
		  {
			  echo $this->getCode();
		  }
			
		
	}

?>
